package com.ruoyi.project.kpi.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.project.device.space.domain.BasCargoSpace;
import com.ruoyi.project.kpi.service.KpiService;
import com.ruoyi.project.mydo.mydojob.domain.MydoJobFinish;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * kpi分析controller
 *
 * @author
 * @create 2020-02-27 11:34
 */
@Controller
@RequestMapping("/kpi")
public class KpiController extends BaseController {

    private String prefix = "kpi";
    @Autowired
    private KpiService kpiService;

    @GetMapping("/spaceAnalysis")
    public String cargo()
    {
        return prefix + "/spaceAnalysis";
    }

    @GetMapping("/spacePlan")
    public String stock()
    {
        return prefix + "/spacePlan";
    }

    @GetMapping("/inAnalysis")
    public String inAnalysis()
    {
        return prefix + "/inAnalysis";
    }

    @GetMapping("/outAnalysis")
    public String outAnalysis()
    {
        return prefix + "/outAnalysis";
    }

    @GetMapping("/ddjAnalysis")
    public String ddjAnalysis()
    {
        return prefix + "/ddjAnalysis";
    }

    @GetMapping("/roadwayAnalysis")
    public String roadwayAnalysis() {
        return prefix + "/roadwayAnalysis";
    }

    /**
     * 货位分析
     *
     * @return
     */
    @RequestMapping("/cs")
    @ResponseBody
    public Map<String, Long> getCargoSpaceAnalysis(BasCargoSpace basCargoSpace) {
            Map<String, Long> map = kpiService.getCargoSpaceAnalysis(basCargoSpace);
            return map;
        }

    @RequestMapping("/plan")
    @ResponseBody
    public Map<String, Object> getsSJJ(BasCargoSpace basCargoSpace) {
        Map<String, Object> plan = kpiService.getCargoSpacePlan(basCargoSpace);
        return plan;
    }

    /**
     * 平面图悬浮数据获取
     * @return
     */
    @RequestMapping("/msg")
    @ResponseBody
    public String getMessage(BasCargoSpace space){
        return kpiService.getMessage(space);
    }

    @RequestMapping("/in")
    @ResponseBody
    public Map<String, long[]> getInAnalysis(MydoJobFinish mydoJobFinish) {
        Map<String, long[]> in = kpiService.getMydojobFinish(mydoJobFinish,10);
        return in;
    }

    @RequestMapping("/out")
    @ResponseBody
    public Map<String, long[]> getOutAnalysis(MydoJobFinish mydoJobFinish) {
        Map<String, long[]> in = kpiService.getMydojobFinish(mydoJobFinish,20);
        return in;
    }

    @RequestMapping("/roadway")
    @ResponseBody
    public Map<String, String[]> getroadway(String warehouseId) {
        Map<String, String[]> in = kpiService.getRoadway(warehouseId);
        return in;
    }

    @RequestMapping("/ddj")
    @ResponseBody
    public Map<String, long[]> getddjAnalysis(MydoJobFinish mydoJobFinish) {
        Map<String, long[]> in = kpiService.getDdjFinish(mydoJobFinish);
        return in;
    }

    /**
     * 巷道均衡分析
     *
     * @return
     */
    @RequestMapping("/ra")
    @ResponseBody
    public Map<String, long[]> getInAnalysis (String startTime, String finishTime, String warehouseId){
        long[] in = kpiService.getMydojobFinish(startTime, finishTime,10,warehouseId);
        long[] out = kpiService.getMydojobFinish(startTime, finishTime,20,warehouseId);
        Map<String,long[]> inorout = new HashMap<>();
        inorout.put("in",in);
        inorout.put("out",out);
        return inorout;
    }
}
